<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
<link type="text/css" rel="stylesheet" href="<%=contextPath %>/static/bootstrap-fileinput/css/fileinput.css" />
<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/fileinput.js"></script>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post"
			enctype="multipart/form-data">
					<div class="form-group">
				<label class="col-sm-3 control-label">文件名：</label>
				<div class="col-sm-4">
				    <input type="text" class="form-control" name="filePath" id="filePath" readonly="readonly"/>
				</div>
				<div class="col-sm-4" style="margin-top: 5px;">
					<input type="file" name="file" id="file" style="float: left;"/>
					<button type="button" class="btn-sm btn-warning" onclick="uploadfile();" style="float: right;">上传</button>
				</div>	
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司名：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="companyName" name="companyName" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属城市：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="city" name="city" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">更新年份：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="years" name="years" value="${nowYear }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">联系方式：</label>
				<div class="col-sm-8">
					<input type="radio" checked="checked" name="contact" value="1">座机
					<input type="radio" name="contact" value="2">手机
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">人数：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="num" name="num" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" />
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
    $(function () {
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('filePath','文件名未填写!'),
        	  new Array('companyName','公司名未填写!'),
        	  new Array('city','所属城市未填写!'),
        	  new Array('years','更新年份未填写!'),
        	  new Array('contact','联系方式未填写!'),
        	  new Array('integral','下载积分未填写!'),
        	  new Array('num','人数未填写!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/companyBook/add',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
	});
    function uploadfile() {
    	var formData = new FormData();
        formData.append("files", $("#file")[0].files[0]);
    	$.ajax({
  	  	         type:'POST',
  	  	         url:'<%=contextPath%>/upload/uploadFile',
  	  	         data:formData,
  	  	         contentType:false,
  	  	         processData:false,//这个很有必要，不然不行
  	  	         dataType:"json",
  	  	         mimeType:"multipart/form-data",
  	  	         success:function(data){
  	  		      console.log(data);
  	  	                if(data.code==200){
  	  	                    $("#filePath").val(data.path);
  	  	                }
  	  	            }
  	  	     });
	}
    
	</script>
</body>
</html>